package com.ws.shop.util;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.log4j.Logger;

public class JdbcUtil {
	private static Logger log = Logger.getLogger(JdbcUtil.class);
	
	public static void close(ResultSet rs,Statement stmt,Connection conn){
		try {
			if(rs!=null)rs.close();
			if(stmt!=null) stmt.close();
			if(conn!=null)conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public static void rollback(Connection conn){
		if(conn != null)
			try {
				conn.rollback();
			} catch (SQLException e) {
				log.error("数据库资源回滚失败JdbcUtil.rollback",e);
			}
	}
	
	public static void closeConnection(Connection conn){
		try{
			if(conn!=null)conn.close();
		}catch(Exception e){
			log.error("数据库资源关闭失败JdbcUtil.closeConnection",e);
		}
	}
	
	public static void closeResultSet(ResultSet rs){
		try{
			if(rs!=null)rs.close();
		}catch(Exception e){
			log.error("数据库资源关闭失败JdbcUtil.closeResultSet",e);
		}
	}
	
	public static void closeStatement(Statement stmt){
		try{
			if(stmt!=null) stmt.close();
		}catch(Exception e){
			log.error("数据库资源关闭失败JdbcUtil.closeStatement",e);
		}
	}
}
